package PL.practica8;

import java.io.IOException;

import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;



public class Procesador {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws RecognitionException 
	 */
	public static void main(String[] args) throws IOException, RecognitionException {
		if (args[0].endsWith(".txt")){
			System.out.println ("Analizando fichero Expresiones");
			CharStream cs = new ANTLRFileStream(args[0]);
			ExpresionesLexer lex = new ExpresionesLexer(cs);
			CommonTokenStream tokens = new CommonTokenStream(lex);
			ExpresionesParser parser = new ExpresionesParser(tokens);
			parser.entrada();
		}
		if (args[0].endsWith(".xml")){
			System.out.println ("Analizando fichero XML");
			CharStream cs = new ANTLRFileStream(args[0]);
			XMLLexer lex = new XMLLexer(cs);
			CommonTokenStream tokens = new CommonTokenStream(lex);
			XMLParser parser = new XMLParser(tokens);
			parser.entrada();
		}
		if (args[0].endsWith(".c")){
			System.out.println ("Analizando fichero c");
			CharStream cs = new ANTLRFileStream(args[0]);
			cFormatLexer lex = new cFormatLexer(cs);
			CommonTokenStream tokens = new CommonTokenStream(lex);
			cFormatParser parser = new cFormatParser(tokens);
			parser.entrada();
			System.out.println ("Salida formateada;");
			System.out.println(parser.getResult());
		}
		if (args[0].endsWith(".java")){
			System.out.println ("Analizando fichero java");
			CharStream cs = new ANTLRFileStream(args[0]);
			javaLexer lex = new javaLexer(cs);
			CommonTokenStream tokens = new CommonTokenStream(lex);
			javaParser parser = new javaParser(tokens);
			parser.entrada();

			System.out.println(parser.isBreakFound());
		}
		System.out.println ("done!!!!!!!");
	}
}


